Build CollectionRef manually
authorFelix Krull <f_krull@gmx.de>
Sat, 18 May 2019 11:57:50 +0000 (13:57 +0200)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:53 +0000 (12:53 -0400)
That way we can get Eq and Hash.

rust-bindings/rust/conf/ostree.toml
rust-bindings/rust/gir-files/OSTree-1.0.gir
rust-bindings/rust/src/auto/collection_ref.rs [deleted file]
rust-bindings/rust/src/auto/mod.rs
rust-bindings/rust/src/collection_ref.rs [new file with mode: 0644]
rust-bindings/rust/src/lib.rs

index 75b89e1b797f45c5538a883b3e7682c1f50869c8..d2c01499cfcd8b0b70f56dcee54f41bfe6b004ed 100644 (file)
@@ -53,9 +53,15 @@ manual = [
 
 [[object]]
 name = "OSTree.CollectionRef"
-status = "generate"
+status = "manual"
+    [[object.function]]
+    # helper functions for NULL-terminated arrays
+    pattern = "dupv|freev"
+    ignore = true
+
     [[object.function]]
-    pattern = "dupv|equal|freev|hash"
+    # we get this for free?
+    name = "dup"
     ignore = true
 
 [[object]]
index 6257837a346ed590eaf905335a48a713b91868c8..33df3aa38deee2a2718e3a2512971d28aa26587c 100644 (file)
@@ -995,17 +995,11 @@ ref name, and %FALSE otherwise. Both @ref1 and @ref2 must be non-%NULL.</doc>
           <type name="gboolean" c:type="gboolean"/>
         </return-value>
         <parameters>
-          <parameter name="ref1"
-                     transfer-ownership="none"
-                     nullable="1"
-                     allow-none="1">
+          <parameter name="ref1" transfer-ownership="none">
             <doc xml:space="preserve">an #OstreeCollectionRef</doc>
             <type name="gpointer" c:type="gconstpointer"/>
           </parameter>
-          <parameter name="ref2"
-                     transfer-ownership="none"
-                     nullable="1"
-                     allow-none="1">
+          <parameter name="ref2" transfer-ownership="none">
             <doc xml:space="preserve">another #OstreeCollectionRef</doc>
             <type name="gpointer" c:type="gconstpointer"/>
           </parameter>
@@ -1038,10 +1032,7 @@ must be %NULL-terminated; it may be empty, but must not be %NULL.</doc>
           <type name="guint" c:type="guint"/>
         </return-value>
         <parameters>
-          <parameter name="ref"
-                     transfer-ownership="none"
-                     nullable="1"
-                     allow-none="1">
+          <parameter name="ref" transfer-ownership="none">
             <doc xml:space="preserve">an #OstreeCollectionRef</doc>
             <type name="gpointer" c:type="gconstpointer"/>
           </parameter>
@@ -11550,17 +11541,11 @@ ref name, and %FALSE otherwise. Both @ref1 and @ref2 must be non-%NULL.</doc>
         <type name="gboolean" c:type="gboolean"/>
       </return-value>
       <parameters>
-        <parameter name="ref1"
-                   transfer-ownership="none"
-                   nullable="1"
-                   allow-none="1">
+        <parameter name="ref1" transfer-ownership="none">
           <doc xml:space="preserve">an #OstreeCollectionRef</doc>
           <type name="gpointer" c:type="gconstpointer"/>
         </parameter>
-        <parameter name="ref2"
-                   transfer-ownership="none"
-                   nullable="1"
-                   allow-none="1">
+        <parameter name="ref2" transfer-ownership="none">
           <doc xml:space="preserve">another #OstreeCollectionRef</doc>
           <type name="gpointer" c:type="gconstpointer"/>
         </parameter>
@@ -11595,10 +11580,7 @@ must be %NULL-terminated; it may be empty, but must not be %NULL.</doc>
         <type name="guint" c:type="guint"/>
       </return-value>
       <parameters>
-        <parameter name="ref"
-                   transfer-ownership="none"
-                   nullable="1"
-                   allow-none="1">
+        <parameter name="ref" transfer-ownership="none">
           <doc xml:space="preserve">an #OstreeCollectionRef</doc>
           <type name="gpointer" c:type="gconstpointer"/>
         </parameter>
diff --git a/rust-bindings/rust/src/auto/collection_ref.rs b/rust-bindings/rust/src/auto/collection_ref.rs
deleted file mode 100644 (file)
index 892d141..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// This file was generated by gir (https://github.com/gtk-rs/gir)
-// from gir-files (https://github.com/gtk-rs/gir-files)
-// DO NOT EDIT
-
-use ffi;
-use glib::translate::*;
-use glib_ffi;
-use gobject_ffi;
-use std::mem;
-use std::ptr;
-
-glib_wrapper! {
-    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
-    pub struct CollectionRef(Boxed<ffi::OstreeCollectionRef>);
-
-    match fn {
-        copy => |ptr| gobject_ffi::g_boxed_copy(ffi::ostree_collection_ref_get_type(), ptr as *mut _) as *mut ffi::OstreeCollectionRef,
-        free => |ptr| gobject_ffi::g_boxed_free(ffi::ostree_collection_ref_get_type(), ptr as *mut _),
-        get_type => || ffi::ostree_collection_ref_get_type(),
-    }
-}
-
-impl CollectionRef {
-    #[cfg(any(feature = "v2018_6", feature = "dox"))]
-    pub fn new<'a, P: Into<Option<&'a str>>>(collection_id: P, ref_name: &str) -> CollectionRef {
-        let collection_id = collection_id.into();
-        let collection_id = collection_id.to_glib_none();
-        unsafe {
-            from_glib_full(ffi::ostree_collection_ref_new(collection_id.0, ref_name.to_glib_none().0))
-        }
-    }
-
-    #[cfg(any(feature = "v2018_6", feature = "dox"))]
-    pub fn dup(&self) -> Option<CollectionRef> {
-        unsafe {
-            from_glib_full(ffi::ostree_collection_ref_dup(self.to_glib_none().0))
-        }
-    }
-}
index 400198f2d9779984d6e9b267a008351c7c458ab9..9673664b1cd5f1ec583ac69bf88fd7678d77b261 100644 (file)
@@ -26,11 +26,6 @@ mod se_policy;
 pub use self::se_policy::SePolicy;
 pub use self::se_policy::SePolicyExt;
 
-#[cfg(any(feature = "v2018_6", feature = "dox"))]
-mod collection_ref;
-#[cfg(any(feature = "v2018_6", feature = "dox"))]
-pub use self::collection_ref::CollectionRef;
-
 #[cfg(any(feature = "v2018_6", feature = "dox"))]
 mod remote;
 #[cfg(any(feature = "v2018_6", feature = "dox"))]
diff --git a/rust-bindings/rust/src/collection_ref.rs b/rust-bindings/rust/src/collection_ref.rs
new file mode 100644 (file)
index 0000000..27374e3
--- /dev/null
@@ -0,0 +1,62 @@
+// Based on a file generated by gir. Changes are marked below.
+use ffi;
+use glib::translate::*;
+use glib_ffi;
+use gobject_ffi;
+use std::hash;
+use std::mem;
+use std::ptr;
+
+glib_wrapper! {
+    #[derive(Debug, PartialOrd, Ord)]
+    pub struct CollectionRef(Boxed<ffi::OstreeCollectionRef>);
+
+    match fn {
+        copy => |ptr| gobject_ffi::g_boxed_copy(ffi::ostree_collection_ref_get_type(), ptr as *mut _) as *mut ffi::OstreeCollectionRef,
+        free => |ptr| gobject_ffi::g_boxed_free(ffi::ostree_collection_ref_get_type(), ptr as *mut _),
+        get_type => || ffi::ostree_collection_ref_get_type(),
+    }
+}
+
+impl CollectionRef {
+    #[cfg(any(feature = "v2018_6", feature = "dox"))]
+    pub fn new<'a, P: Into<Option<&'a str>>>(collection_id: P, ref_name: &str) -> CollectionRef {
+        let collection_id = collection_id.into();
+        let collection_id = collection_id.to_glib_none();
+        unsafe {
+            from_glib_full(ffi::ostree_collection_ref_new(collection_id.0, ref_name.to_glib_none().0))
+        }
+    }
+
+    #[cfg(any(feature = "v2018_6", feature = "dox"))]
+    fn equal(&self, ref2: &CollectionRef) -> bool {
+        unsafe {
+            // CHANGE: both instances of *mut to *const
+            from_glib(ffi::ostree_collection_ref_equal(ToGlibPtr::<*const ffi::OstreeCollectionRef>::to_glib_none(self).0 as glib_ffi::gconstpointer, ToGlibPtr::<*const ffi::OstreeCollectionRef>::to_glib_none(ref2).0 as glib_ffi::gconstpointer))
+        }
+    }
+
+    #[cfg(any(feature = "v2018_6", feature = "dox"))]
+    fn hash(&self) -> u32 {
+        unsafe {
+            // CHANGE: *mut to *const
+            ffi::ostree_collection_ref_hash(ToGlibPtr::<*const ffi::OstreeCollectionRef>::to_glib_none(self).0 as glib_ffi::gconstpointer)
+        }
+    }
+}
+
+impl PartialEq for CollectionRef {
+    #[inline]
+    fn eq(&self, other: &Self) -> bool {
+        self.equal(other)
+    }
+}
+
+impl Eq for CollectionRef {}
+
+impl hash::Hash for CollectionRef {
+    #[inline]
+    fn hash<H>(&self, state: &mut H) where H: hash::Hasher {
+        hash::Hash::hash(&self.hash(), state)
+    }
+}
index 12b99db1ec6d11e5afe57d8dff837173a45b10c3..2e6e77bb097232cf8c28bc78f5b7545b80cad242 100644 (file)
@@ -14,18 +14,22 @@ extern crate lazy_static;
 use glib::Error;
 
 // re-exports
-#[cfg_attr(feature = "cargo-clippy", allow(clippy))]
 mod auto;
-pub use auto::functions::*;
-pub use auto::*;
+pub use crate::auto::functions::*;
+pub use crate::auto::*;
 
 mod repo;
 
+#[cfg(any(feature = "v2018_6", feature = "dox"))]
+mod collection_ref;
+#[cfg(any(feature = "v2018_6", feature = "dox"))]
+pub use crate::collection_ref::CollectionRef;
+
 mod object_name;
-pub use object_name::ObjectName;
+pub use crate::object_name::ObjectName;
 
 // public modules
 pub mod prelude {
-    pub use auto::traits::*;
-    pub use repo::RepoExtManual;
+    pub use crate::auto::traits::*;
+    pub use crate::repo::RepoExtManual;
 }